package com.ffz.springbootvuedemo.controller;

import com.ffz.springbootvuedemo.bean.Result;
import com.ffz.springbootvuedemo.bean.User;
import com.ffz.springbootvuedemo.bean.vo.UserEditVO;
import com.ffz.springbootvuedemo.bean.vo.UserVO;
import com.ffz.springbootvuedemo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: fengfazheng
 * @create: 2021-12-28 23:45
 **/
@RestController
@RequestMapping("/user")
@Api(value = "/user", tags = "用户信息")
public class UserController extends BaseController {
    @Autowired
    private UserService userService;

    @PostMapping("/create")
    @ApiOperation(value = "新增用户", httpMethod = "POST", notes = "新增用户")
    public Result<String> create(@RequestBody UserVO userVO) {
        userService.create(userVO);
        return resultOk();
    }
    @PutMapping("/updateById")
    @ApiOperation(value = "新增用户", httpMethod = "PUT", notes = "更新用户信息")
    public Result<String> updateById(@RequestBody UserEditVO userVO) {
        userService.updateById(userVO);
        return resultOk();
    }
    @GetMapping("/getAll")
    @ApiOperation(value = "查询用户", httpMethod = "GET", notes = "查询用户")
    public Result<Page<User>> getAll(@RequestParam Integer pageNum,
                                     @RequestParam Integer pageSize,
                                     @RequestParam(required = false) String key) {
        return resultOk(userService.getAll(pageNum-1,pageSize,key));
    }
    @DeleteMapping("/deleteById")
    @ApiOperation(value = "按照ID删除", httpMethod = "DELETE", notes = "按照ID删除")
    public Result<String> deleteById(@RequestParam String id) {
        userService.deleteById(id);
        return resultOk();
    }
}
